/******************************************************************************/
//	AppCore.h	-	Controls all aspects of the program
//						(Entry, Rendering, Updates)
//
//	Author:		Russell Klinkerman
//	Created:	02.24.2004			Updated: 12.02.04
/******************************************************************************/

#ifndef _APPCORE_H_
#define _APPCORE_H_

#include <windows.h>						//	Needed for Windows Applications.

#include "Direct3DManager.h"

#include "ObjectBase.h"
#include "Actor.h"

#pragma comment(lib, "winmm.lib")			//	For timeGetTime()

/********/
/*MACROS*/
/********/

// Macro to safely relase a COM object.
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)	if(p){ p->Release(); p = NULL; }
#endif

/*********/
/*CLASSES*/
/*********/

// The Core Application Class
class	CAppCore : public CObjectBase
{
	private:

		HWND					m_hWnd;					// Handle to Application Window.
		HINSTANCE				m_hInstance;			// Handle to Application Instance.
		int						m_nWidth, m_nHeight;	// Height & Width of Application Window.
		bool					m_bFullScreen;			// Fullscreen Flag.

		CActor					m_ChunLi;	// Our featured character.

		// GUI elements
		CDxImage	dxiAppTitle;	// Static image for app title
		D3DXMATRIX	mAppTitle;

	public:

		friend BOOL CALLBACK FSMDialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

		/******************************************************************************/
		//	Init	-	Initializes the Application Core.
		/******************************************************************************/
		void	Init();

		/******************************************************************************/
		//	Update	-	Update application
		//
		//	Return:	TRUE if successful
		/******************************************************************************/
		bool	Update();

		/******************************************************************************/
		//	Draw	-	Draw everything in the application
		/******************************************************************************/
		void	Draw();

		/******************************************************************************/
		//	Shutdown	-	Shutdown the Application Core.
		/******************************************************************************/
		void	Shutdown();

		/*************/
		/* ACCESSORS */

		// GetWnd	-	Return the application's handle to the window.
		HWND	GetWnd() { return m_hWnd; }

		// GetInstance	-	Return the application's instance handle.
		HINSTANCE GetInstance() { return m_hInstance; }

		// GetWndWidth	-	Return the application's window width.
		int		GetWndWidth()	{	return m_nWidth;	}

		// GetWndHeight	-	Return the application's window height.
		int		GetWndHeight()	{	return m_nHeight;	}

		// GetFullScreen	-	Returns TRUE if app is running full screen.
		bool	GetFullScreen()	{	return m_bFullScreen;	}

		/*************/
		/* MODIFIERS */

		// SetWnd			-	Sets the window handle to be used application-wide
		void	SetWnd(HWND	_hWnd)	{	m_hWnd = _hWnd;	};

		// SetInstance		-	Sets the instance handle to be used application-wide
		void	SetInstance(HINSTANCE _hInstance)	{	m_hInstance = _hInstance;	}

		// SetDimensions	-	Sets the Width & Height of the Application
		void	SetDimensions(int	_nWidth, int	_nHeight)
		{
			m_nWidth	= _nWidth;
			m_nHeight	= _nHeight; 
		}

		// SetFullScreen	-	Sets the FullScreen flag of the Application
		void	SetFullScreen(bool	_bFS)	{	m_bFullScreen = _bFS;	}

};

extern	CAppCore	appCore;

/******************************************************************************/
//	WindowProc	-	Processes Windows Messages
//
//	In:		hwnd
//			msg
//			wparam
//			lparam
//	Out:
//	Return:	LRESULT
/******************************************************************************/
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
BOOL CALLBACK FSMDialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

#endif